<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise学习2</title>
</head>
<script>
    function runAsync1() {
        var p = new Promise(function (resolve, reject) {
            console.log('任务1执行完成');
            resolve('随便什么数据1');
        });
        return p;
    }

    runAsync1()
        .then(function (data) {
            console.log(data);
            return '直接返回数据1';
        })
        .then(function (data) {
            console.log(data);
            return '直接返回数据2';
        })
        .then(function (data) {
            console.log(data);
        });

    function rejectPromise() {
        var p = new Promise(function (resolve, reject) {
            reject('数字太大了');
        })
        return p;
    }

    rejectPromise()
        .then(
        function (data) {
            console.log('resolved');
            console.log(data);
        },
        function (reason, data) {
            console.log('rejected');
            console.log([reason, data]);
        }
        );
</script>

<body>
    <article>
        <h1>Promise学习</h1>
    </article>
</body>

</html>